#include <SDL/SDL.h>
// To load PNG files.
#include <SDL/SDL_image.h>
#include <stdio.h>

int main ()
{
  SDL_Surface *screen;
  SDL_Surface *image;
  SDL_RWops *rwop;
  SDL_Rect src, dest;

  // Init SDL's video system.
  if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    printf("Unable to initialize SDL: %s\n", SDL_GetError());
    return 1;
  }
  
  // Call SDL_Quite when the program exists.
  atexit(SDL_Quit);

  // Set the video mode.
  screen = SDL_SetVideoMode(1440, 900, 16, SDL_FULLSCREEN);
  if (screen == NULL) {
    printf("Unable to set video mode: %s\n", SDL_GetError());
    return 1;
  }

  // Load the png image.
  rwop = SDL_RWFromFile("../data/debian.png", "rb");
  image = (SDL_Surface*)IMG_LoadPNG_RW(rwop);
  if (image == NULL) {
    printf("IMG_LoadPNG_RW: %s\n", IMG_GetError());
    return 1;
  }

  // How much data to copy?
  src.x = 0; 
  src.y = 0;
  // Copy the entire image.
  src.w = image->w;
  src.h = image->h;

  dest.x = 0; 
  dest.y = 0;
  dest.w = image->w;
  dest.h = image->h;

  // Draw the bitmap to the screen.
  SDL_BlitSurface(image, &src, screen, &dest);

  // Ask SDL to update the scren.
  SDL_UpdateRect(screen, 0, 0, 0, 0);
  
  // 3,000 ms pause.
  SDL_Delay(3000);

  // Free memory.
  SDL_FreeSurface(image);

  return 0;
}
